package com.lin.task;

import com.lin.blog.service.IElasticSearchService;
import com.lin.constant.ResultCode;
import com.lin.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: blog
 * @description: 文章定时存储到ElasticSearch
 * @author: Lin
 * @create: 2020-05-15 16:25
 **/
@Slf4j
public class Article2ESTask extends QuartzJobBean {

    @Autowired
    private IElasticSearchService elasticSearchService;

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        log.info("Article2ESTask-------- {}", sdf.format(new Date()));

        Result result = elasticSearchService.importArticleData();

        if (ResultCode.SUCCESS.getCode().equals(result.getCode())){
            log.info("Article2ESTask  {}-------- {}", result.getMessage(),sdf.format(new Date()));
        }else{
            log.info("Article2ESTask  {}-------- {}",result.getMessage(),  sdf.format(new Date()));
        }

    }
}
